<template>
  <div class="myContainer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>
      <el-col :span="12" class="myTextAlignRight">
        <el-button type="primary" class="myBgGreen" @click="onAdd" v-if="isShow(140)">新增</el-button>
        <!-- <el-button type="primary" class="myBgGreen" @click="onHistorical">历史记录</el-button> -->
      </el-col>
    </el-row>    
    <el-row class="myMarginTop_10px">
      <el-col :span="24">
        <el-table
          v-loading="loading"
          ref="multipleTable"
          :data="tableData"
          :border = true
          :stripe = true
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="50">
          </el-table-column>
          <el-table-column
            label="序号"
            type="index"
            width="100">
          </el-table-column>
          <el-table-column
          	prop="title"
            label="标题"
            >
          </el-table-column> 
          <el-table-column
          	prop="extra_desc"
            label="描述"
            >
          </el-table-column> 
          <el-table-column
            width="100"
            label="缩略图">
            <template scope="scope">
              <a :href='scope.row.thumbnail' target="_blank">
                <img :src='scope.row.thumbnail' width="50" height="50"/>
              </a>
            </template>
          </el-table-column> 
          <el-table-column
          	prop="create_time"
            label="创建时间"
            >
          </el-table-column>
          <el-table-column
            width="100"
            label="状态">
            <template scope="scope">
              <span v-if="scope.row.status==0">禁用</span>
              <span v-else>启用</span>
            </template>
          </el-table-column>
          <el-table-column
          	prop="publish_name"
            label="创建人"
            >
          </el-table-column>
          <el-table-column
          	prop="pos"
            width="120"
            label="位置"
            >
          </el-table-column>
          <el-table-column
            label="操作"
            width="120">
            <template scope="scope">
              <el-button type="text"  class="look" size="small" @click="onInfo(scope.row.banner_id)">详情</el-button> 	
              | <el-button type="text primary"  class="look" size="small" @click="onUpdate(scope.row.banner_id)" v-if="isShow(141)">编辑</el-button>
              | <el-button type="text warning"  class="look" size="small" @click="onDelete(scope.row.banner_id)" v-if="isShow(142)">删除</el-button> 
            </template>
          </el-table-column>
        </el-table>
        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>

	  <!-- <el-button type="text" @click="boutiqueDialog=true" class="look" size="small">[精品推荐]详情/编辑</el-button> 
    <el-button type="text" @click="onBanner(123)" class="look" size="small">[banner]详情/编辑</el-button> --> 

	  <!-- <el-dialog title="精品推荐" class="myRoleDialog" :visible.sync="boutiqueDialog">
      <el-row class="myMarginBottom_10px">
        <el-col :span="6" class="myLeftMsg">
       	  <span class="require myVA_M">*</span> 标题
       	</el-col>
        <el-col :span="17">	
		      <el-input placeholder="请输入标题"></el-input>
        </el-col>
      </el-row>
      <el-row class="myMarginBottom_10px">
        <el-col :span="6" class="myLeftMsg">
       	  <span class="require myVA_M">*</span> 描述
       	</el-col>
        <el-col :span="17">	
		      <el-input placeholder="请输入描述" type="textarea"></el-input>
        </el-col>
      </el-row>
      <el-row class="myMarginBottom_10px">
        <el-col :span="6" class="myLeftMsg">
          <span class="require myVA_M">*</span> 发布时间
        </el-col>
        <el-col :span="17"> 
          <el-date-picker
            v-model="time"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="发布时间">
          </el-date-picker>
        </el-col>
      </el-row>
      <el-row class="myMarginBottom_10px">
        <el-col :span="6" class="myLeftMsg">
          <span class="require myVA_M">*</span> 图片
        </el-col>
        <el-col :span="17"> 
          <el-upload
            class="avatar-uploader"
            :action="responseUrl"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-col>
      </el-row>
      <el-row class="myMarginBottom_10px">
        <el-col :span="6" class="myLeftMsg">
          <span class="require myVA_M">*</span> 商品/页面ID
        </el-col>
        <el-col :span="17"> 
          <el-input placeholder="请输入商品/页面ID"></el-input>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" class="myBgGreen" @click="boutiqueDialog = false">取 消</el-button>
        <el-button type="primary" class="myBgGreen" >关 闭</el-button>
        <el-button type="primary" class="myBgGreen" >保 存</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
  .myColorRed{
    color: #f00;
  }
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
    padding-right: 10px;
  }
  .myMarginBottom_10px{
  	margin-bottom: 10px;
  }
  .myVA_M{
    vertical-align: middle;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
    border:1px solid #d8dce5;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

<script>
  import { getBannerList , deleteBanner } from "@/api/contentMGT";
  export default {
    data(){
      return{  
        title:"广告位管理",    
        tableData:[],  
        total:null, //总条数  
        page_num: null, //当前页码
        page_size: null, //每页显示多少条 
        kw:"",
        time:"",
        range:"",
        rangeList:[],
        type:"",
        typeList:[],
        boutiqueDialog:false,
        responseUrl:"",
        imageUrl:"",
        loading:false
      }
    },
    created() {
      document.title=this.title;
      this.onGetBannerList();
    },
    filters: {
    },
    methods:{
      onSearch() {//查询
      },
      handleSizeChange(val) {
        this.page_size = val;
        this.onGetBannerList();
      },
      handleCurrentChange(val) {
        let pageNum=window.localStorage.getItem("pageNum");
        if(pageNum){
          this.page_num = Number(pageNum);
          window.localStorage.removeItem("pageNum");
        }else{
          this.page_num = val;
        }
        this.onGetBannerList();
      },
      handleSelectionChange(val) {
      },
      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
        this.saveImageUrl=res.saveUrl;
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;
        if (!isJPG) {
          this.$message.error('上传的广告图只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传的广告图大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      onHistorical(){
        this.$router.push({
          path:"/adHistorical"
        })
      },
      onBanner(b_id){
        this.$router.push({
          path:"/",
          query:{type:'info', id: b_id}
        })
      },
      onGetBannerList(){//拉取列表
        let vm=this;
        let params={
          page_num:vm.page_num,
          page_size:vm.page_size
        }
        vm.loading=true;
        getBannerList(params).then(response => {
          let res=response.data;
          vm.page_num=res.page_num;
          vm.page_size=res.page_size;
          vm.total=res.total;
          vm.tableData=res.rows;
          vm.loading=false;
          // console.log(res)
        }).catch(error => {
          vm.loading=false;
          // console.log(error)
        })
      },
      onAdd(){//新增
        this.$router.push({
          path:"/bannerComponents",
          query: {type: 'add', pageNum: this.page_num}
        })
      },
      onInfo(b_id){//详情
        this.$router.push({
          path:"/bannerComponents",
          query: {type: 'info',id:b_id, pageNum: this.page_num}
        })
      },
      onUpdate(b_id){//修改
        this.$router.push({
          path:"/bannerComponents",
          query: {type: 'update',id:b_id, pageNum: this.page_num}
        })
      },
      onDelete(b_id){//删除
        let vm=this;
        vm.$confirm('您确定要删除这条数据吗？', '提示', {//弹出框
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteBanner(b_id).then(response => {
            vm.$message.success('执行成功!');
            vm.onGetBannerList();
          }).catch(error => {
            vm.$message.error("执行失败！");
          })
        }).catch(() => {
          vm.$message({
            type: 'info',
            message: '已取消执行'
          });          
        });
      }
    }

  }


</script>



